3D Graphics Programming with QuickDraw 3D 1.5.4
Previous | QD3D Book | Overview | Chapter Contents | Next
You send all drawing commands to a draw context. To create a draw context, you need to specify a virtual device and a drawing engine. This section shows how to initialize a virtual device. See the next section for information on specifying a drawing engine.
On Macintosh computers, a virtual device represents either an area of memory, a video device, or an offscreen graphics world. You specify a virtual device by filling in fields of a device structure, defined by the TQADevice data type.
typedef struct TQADevice {
TQADeviceType deviceType;
TQAPlatformDevice device;
} TQADevice;
The deviceType field indicates the type of virtual device you want to draw into. Currently, you can pass either kQADeviceMemory or kQADeviceGDevice to select a Macintosh device type. The device field indicates a platform device data structure, which is either of type TQADeviceMemory for memory devices or GDHandle for graphics devices.
typedef union TQAPlatformDevice {
TQADeviceMemory memoryDevice;
GDHandle gDevice;
} TQAPlatformDevice;
To specify a memory device, you fill in the fields of a memory device structure, defined by the TQADeviceMemory data type.
typedef struct TQADeviceMemory {
long rowBytes;
TQAImagePixelType pixelType;
long width;
long height;
void *baseAddr;
} TQADeviceMemory;
Listing 4 shows how to initialize a memory device.
Listing 4 Initializing a memory device
TQADevice myDevice;
long myTargetMemory[100][100];
myDevice.deviceType = kQADeviceMemory;
myDevice.device.memoryDevice.rowBytes = 100 * sizeof(long);
myDevice.device.memoryDevice.pixelType = kQAPixel_ARGB32;
myDevice.device.memoryDevice.width = 100;
myDevice.device.memoryDevice.height = 100;
myDevice.device.memoryDevice.baseAddr = myTargetMemory;
Drawing to memory always occurs in the native pixel format of the platform. Note that not all drawing engines support drawing to memory. For information on determining what kinds of virtual devices a particular drawing engine supports, see "Finding a Drawing Engine" .
Listing 5 shows how to initialize a virtual graphics device.
Listing 5 Initializing a graphics device
TQADevice myDevice;
GDHandle gDeviceHandle;
/*create a GDHandle (perhaps by calling NewGDevice)*/
...
myDevice.deviceType = kQADeviceGDevice;
myDevice.device.gDevice = gDeviceHandle;
The code in Listing 5 assumes that the gDeviceHandle global variable has been assigned a handle to a GDevice record. See Inside Macintosh: Imaging With QuickDraw for complete information on creating and configuring graphics devices.
A draw context can be associated with only a single virtual device and hence with only a single GDevice . Macintosh windows can straddle several screens, each associated with a different GDevice . It is your responsibility to determine which graphics devices a window straddles and to create a separate draw context for each one.
Previous | QD3D Book | Overview | Chapter Contents | Next